home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / windows / cm95_10.zip / INTERNET.DLL / TEXT / WILTIME < prev   
Text File  |  1996-10-29  |  4KB  |  152 lines

  1. AddExtender ("WXSock32i.dll")
  2. IntControl (35, 500, 0, 0, 0)
  3. sTitle = "ClockMan GetTime pgm"
  4. bOK = @TRUE
  5. sDial     = "<dialupname>"
  6. nMaxRedial = <numredials>
  7. nRedialDelay = 10
  8. sHost     = "<timeserveraddr>"
  9. sErrDesc  = ""
  10.  
  11.  
  12. ;Dial our host (unless user is on a direct connect)...
  13. hConn = 0
  14. nNumRedials = 0
  15. if (sDial <> "")
  16.     :DialIt
  17.     hConn = DUNConnect (sDial)
  18.     nErr = SGetLastErr ()
  19.     if (!hConn)
  20.         switch nErr
  21.         case @SErrNotFound
  22.             sErrDesc = "Couldn't connect to %sDial%: no such dial-up"
  23.             break
  24.         case @SErrBusy
  25.             if (nNumRedials <= nMaxRedial)
  26.                 nNumRedials = nNumRedials + 1
  27.                 Delay (nRedialDelay)
  28.                 goto DialIt
  29.             else
  30.                 sErrDesc = "Couldn't connect to %sDial%: Line busy"
  31.             endif
  32.             break
  33.         case @SErrNoAnswer
  34.             if (nNumRedials <= nMaxRedial)
  35.                 nNumRedials = nNumRedials + 1
  36.                 Delay (nRedialDelay)
  37.                 goto DialIt
  38.             else
  39.                 sErrDesc = "Couldn't connect to %sDial%: No answer"
  40.             endif
  41.             break
  42.         case @SErrVoice
  43.             sErrDesc = "Couldn't connect to %sDial%: A human answered"
  44.             break
  45.         case nErr ; <--default
  46.             sErrDesc = "Couldn't connect to %sDial% - error %nErr%"
  47.         endswitch
  48.         bOK = @FALSE
  49.         goto LogIt
  50.     else
  51.         if (nErr == @SAlready)
  52.             ; We're already connected. Don't hang up when this event is thru...
  53.             hConn = 0 
  54.         endif
  55.     endif
  56. endif
  57.  
  58.  
  59. ; Create a socket...
  60. hSock = SOpen ()
  61. if (hSock==@SErrSocket)
  62.     nErr = SGetLastErr ()
  63.     sErrDesc = "Couldn't create socket - error %nErr%"
  64.     bOK = @FALSE
  65.     goto HangUp
  66. endif
  67.  
  68. ; Connect it up...
  69. nRet = SConnect (hSock, sHost, "time")
  70. if (nRet <> @TRUE)
  71.     nErr = SGetLastErr ()
  72.     switch nErr
  73.         case @SErrHostName
  74.         sErrDesc = "Host ""%sHost%"" not found. (Misspelled, or no longer exists.)"
  75.         break
  76.  
  77.         case 10060
  78.         sErrDesc = "Timed out trying to connect to ""%sHost%""."
  79.         break
  80.  
  81.         case @SErrBusy
  82.         sErrDesc = "Couldn't connect to ""%sHost%"".%@CRLF%(Server busy.)"
  83.         break
  84.  
  85.         case @SErrNoConn
  86.         sErrDesc = "Couldn't connect to ""%sHost%"".%@CRLF%(Server down, or they don't offer a time server.)"
  87.         break
  88.  
  89.         case nErr ; <--default
  90.         sErrDesc = "Couldn't connect to ""%sHost%"" - WinSock error %nErr%"
  91.     endswitch
  92.  
  93.     bOK = @FALSE
  94.     goto CloseSocket
  95. endif
  96.  
  97. ; Time server sent us the time immediately upon connect...
  98. dwRawTime = SRecvNum32 (hSock)
  99. dwPrevTime = CMGetSysTime ()
  100. if (!dwRawTime)
  101.     ; Oh, maybe they require a CR/LF first like RFC 868 claims they should?...
  102.     SSendLine (hSock, "")
  103.     dwRawTime = SRecvNum32 (hSock)
  104.     dwPrevTime = CMGetSysTime ()
  105. endif
  106.  
  107. if (!dwRawTime)
  108.     sErrDesc = "No response from time server @ ""%sHost%""."
  109.     bOK = @FALSE
  110. else
  111.     ; Immediately update our system time...
  112.     dwNewTime = dwRawTime - 2208988800; Convert to secs since 1/1/70 from 1/1/00
  113.     CMSetSysTime (dwNewTime)
  114. endif
  115.  
  116. ; If user hit Ctrl+Break, WIL will bring us here...
  117. :Cancel
  118.  
  119. ; Close the socket...
  120. :CloseSocket
  121. nRet = SClose (hSock)
  122.  
  123. ; Hang up...
  124. :HangUp
  125. if (hConn)
  126.     nRet = DUNDisconnect (hConn)
  127. endif
  128.  
  129.  
  130. ; Log what we did...
  131. :LogIt
  132. if bOK == @TRUE
  133.     ; Finally, log the adjustment...
  134.     dwOffset = dwNewTime - dwPrevTime
  135.     if (dwOffset > 0)
  136.         sLog = "Turned the clock forward by %dwOffset% seconds"
  137.     else
  138.         if (dwOffset < 0)
  139.             dwOffset = -dwOffset
  140.             sLog = "Turned the clock back by %dwOffset% seconds"
  141.         else
  142.             sLog = "No adjustment needed to the system clock!"
  143.         endif
  144.     endif
  145. else
  146.     sLog = strcat ("Error attempting to adjust time:", @CRLF, sErrDesc)
  147. endif
  148.  
  149. CMLogMessage (sLog)
  150. Display (5, sTitle, sLog)
  151. ~
  152.